/**
 * \* Created with IntelliJ IDEA.
 * \* User: Administrator
 * \* Date: 2022/3/22
 * \* Time: 14:31
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
public class Demo11 {
    public static void main(String[] args) {
        Thread t = new Thread(()->{
            //如果这个标志被设置了，它是被中断的状态 ，则返回true，中断 线程
            while (!Thread.currentThread().isInterrupted()){
                System.out.println("hello world!");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    break;
                }
            }
        });
        t.start();

        //在主线程中，条用interrupt方法，来中断这个线程
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //在主线程中，条用interrupt方法，来中断这个线程
        //t.interupt的意思就是让t线程被中断
        t.interrupt();
    }
}
